#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin


echo "- add dns"
if ! egrep '^nameserver 10.100.1.145' /etc/resolv.conf &>/dev/null ; then
    echo 'nameserver 10.100.1.145' >> /etc/resolv.conf
fi
if ! egrep '^nameserver 10.100.1.235' /etc/resolv.conf &>/dev/null ; then
    echo 'nameserver 10.100.1.235' >> /etc/resolv.conf
fi


echo "- yum repo ..."
curl -s http://mirrors.hunantv.com/install_hunantv_repo.sh | sh

echo "- yum base rpms (ntpdate, proxychains, python-setuptools, python-meld3...) ..."
yum -y install wget ntpdate man proxychains python-setuptools python-meld3 python-devel

echo "- ntp adjust ..."
echo '
driftfile /var/lib/ntp/drift
disable monitor

restrict 127.0.0.1
restrict 127.127.1.0
restrict -6 ::1

restrict  ntp.hunantv.com
restrict  ntp1.hunantv.com
restrict  ntp.openredcloud.com
restrict  ntp1.openredcloud.com
restrict  172.31.7.156
restrict  172.31.2.37

restrict 192.168.1.0 mask 255.255.255.0 nomodify  kod notrap
restrict 192.168.9.0 mask 255.255.255.0 nomodify  kod notrap
restrict 10.100.0.0 mask 255.255.0.0 nomodify     kod notrap

restrict  default ignore

server  172.31.7.156
server  172.31.2.37
server 10.100.1.68
server 10.100.1.69
server 10.100.1.83
server 10.100.1.87

fudge   127.127.1.0 stratum  5  


includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
' > /etc/ntp.conf

chkconfig --add ntpd
chkconfig ntpd on
/etc/init.d/ntpd start

echo "- install pip ..."
easy_install pip

echo "- install and config supervisor .."
pip install supervisor redis
mkdir -p /etc/supervisord.conf.d
if ! [ -f /etc/supervisord.conf ]; then
    wget -q http://mirrors.hunantv.com/d/supervisord.conf -O /etc/supervisord.conf
fi

echo "- java install ..."
if ! [ -d /opt/app/jdk1.7.0_45 ]; then
    mkdir -p /opt/app
    wget -q http://mirrors.hunantv.com/d/jdk-7u45-linux-x64.tar.gz -O /opt/app/jdk-7u45-linux-x64.tar.gz
    cd /opt/app
    tar xzf jdk-7u45-linux-x64.tar.gz -C /opt/app/
fi
if ! egrep '^JAVA_HOME=' /etc/profile &> /dev/null ; then 
    echo '
JAVA_HOME=/opt/app/jdk1.7.0_45
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
' >> /etc/profile
fi

#echo "- install python2.7 ..."
#if ! [ -f /usr/local/bin/python2.7 ] ; then 
#    yum -y install gcc make gcc-c++
#
#    yum -y install  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl
#
#    mkdir -p /opt/src
#    cd /opt/src
#    rm -f Python-2.7.10.tgz
#    wget -q http://mirrors.hunantv.com/d/Python-2.7.10.tgz
#    tar xzf Python-2.7.10.tgz
#    cd Python-2.7.10
#    ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib" --with-ensurepip=install
#    make && make altinstall
#
##    /usr/local/bin/pip2.7 install --upgrade pip
#fi

if ! [ -f /root/.pip/pip.conf ]; then
    mkdir -p /root/.pip
    echo '
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
' >> /root/.pip/pip.conf
fi

#pip2.7 install redis

echo "- install zabbix ..."

echo "- ldap ..."
